package com.salesmonitoring.accounts.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import com.salesmonitoring.connector.Connector;

public class MarketingAssistantRefAoNamDaoImpl {

	private static MarketingAssistantRefAoNamDaoImpl MarketingAssistantRefAoNamDaoImpl;
	private Connection connection;
	private Statement statement;
	private ResultSet rs;
	private String query;
	
	
	public static synchronized MarketingAssistantRefAoNamDaoImpl getInstance() {

		if(MarketingAssistantRefAoNamDaoImpl == null) {
			MarketingAssistantRefAoNamDaoImpl = new MarketingAssistantRefAoNamDaoImpl();
		}
		
		return MarketingAssistantRefAoNamDaoImpl;
	}
	
	public ArrayList<String> getAllAoNam() {
		
		ArrayList<String> rsCodList = new ArrayList<String>();
		rsCodList.add("");
		
		try {
			Connector connector = Connector.getInstance();
			connection = connector.getConnection();
			statement = connection.createStatement();
			query = "SELECT rs_code FROM repair_shop";
			rs = statement.executeQuery(query);
			
			while(rs.next()) {
				rsCodList.add(rs.getString("rs_code"));
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			
			if(rs != null) {
				try{ rs.close(); } catch(Exception e) { e.printStackTrace(); }
			}
			
			if(statement != null) {
				try{ statement.close(); } catch(Exception e) { e.printStackTrace(); }
			}
			
			if(connection != null) {
				try{ connection.close(); } catch(Exception e) { e.printStackTrace(); }
			}
			
		}
		
		return rsCodList;
	}

}
